//
//  DYYuyueNumCell.swift
//  SheYangBigData
//
//  Created by 宋海胜 on 2021/1/5.
//  Copyright © 2021 叁拾叁. All rights reserved.
//



import UIKit

class DYYuyueNumCell: SYBaseCell  {
    
    
    
    var bgView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = UIColor(hex: 0x367FF6)
        v.layer.cornerRadius = 2
        return v
    }()
    
    let nameLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x1E1E1E)
        v.font = 17.autoBoldFontSize()
        v.text = "选择数量"
        
        return v
    }()
    
    var sepView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = Constant.bgViewColor
        return v
    }()
    
    let numLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 18.autoBoldFontSize()
        v.text = "1"
        v.textAlignment = .center
        return v
    }()
    
    let jian: UIButton = {
        let v: UIButton  = UIButton()
        v.setImage(UIImage(named: "jian"), for: .normal)
        return v
    }()
    
    let jia: UIButton = {
        let v: UIButton  = UIButton()
        v.setImage(UIImage(named: "jia"), for: .normal)
        return v
    }()
    
    
    
    public func configureView() {
        
    }
    
    override func initViews() {
        
        jian.addTarget(self, action: #selector(jianAction), for: .touchUpInside)
        jia.addTarget(self, action: #selector(jiaAction), for: .touchUpInside)
        contentView.addSubview(nameLb)
        contentView.addSubview(nameLb)
        contentView.addSubview(jian)
        contentView.addSubview(sepView)
        contentView.addSubview(jia)
        contentView.addSubview(numLb)
        
        contentView.addSubview(bgView)
        
        bgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(20.0.autoWidth())
            make.bottom.equalToSuperview().offset(-30.0.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(14.5))
            make.width.equalTo(4.0.autoWidth())
            make.height.equalTo(15.0.autoWidth())
        }
        nameLb.snp.makeConstraints { (make) in
            make.centerY.equalTo(bgView)
            make.left.equalTo(bgView.snp.right).offset(autoWidth(7.0))
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(16.0.autoWidth())
        }
        
        
        jian.snp.makeConstraints { (make) in
            make.centerY.equalTo(bgView)
            make.right.equalTo(jia.snp.left).offset(autoWidth(-35.0))
            make.width.height.equalTo(22.0.autoWidth())
        }
        jia.snp.makeConstraints { (make) in
            make.centerY.equalTo(bgView)
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.width.height.equalTo(22.0.autoWidth())
        }
        numLb.snp.makeConstraints { (make) in
            make.centerY.equalTo(bgView)
            make.right.equalTo(jia.snp.left).offset(autoWidth(-5.0))
            make.left.equalTo(jian.snp.right).offset(autoWidth(5.0))
            make.height.equalTo(22.0.autoWidth())
        }
        
        
        sepView.snp.makeConstraints { (make) in
            make.top.equalTo(bgView.snp.bottom).offset(autoWidth(20.0))
            make.left.right.equalToSuperview()
            make.height.equalTo(10.0.autoWidth())
            make.bottom.equalToSuperview()
        }
    }
    
    @objc func jianAction() {
        
        let num = Int(numLb.text!)! - 1
        if num > 0 {
            numLb.text = "\(num)"
            self.clickedClosure?(num)
        }
    }
    @objc func jiaAction() {
        
        let num = Int(numLb.text!)! + 1
        numLb.text = "\(num)"
        self.clickedClosure?(num)
    }
}

